
package com.xbongbong.pro.statistic.model.impl;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.pro.domain.dao.ChartCustomDao;
import com.xbongbong.pro.domain.entity.ChartEntity;
import com.xbongbong.pro.statistic.enums.ChartTypeEnum;
import com.xbongbong.pro.statistic.model.ChartCustomModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author autoGen
 * @time 2019-01-07 11:13:40
 */
@Service("chartCustomModel")
public class ChartCustomModelImpl implements ChartCustomModel {

    @Resource
    private ChartCustomDao dao;
    @Override
    public Integer insert(ChartEntity entity){
        long now = DateUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        Integer insert = dao.insert(entity);
        //TODO  返回实体id
        return insert;
    }

    @Override
    public Integer update(ChartEntity entity){
        entity.setUpdateTime((long)DateUtil.getInt());
        //TODO  返回实体id
        return dao.update(entity);
    }

    @Override
    public Integer save(ChartEntity entity) {
        if(entity.getId() == null || entity.getId().equals(0L)) {
            return insert(entity);
        }
        return update(entity);
    }

    @Override
    public void insertBatch(List<ChartEntity> entityList) {
        dao.insertBatch(entityList);
    }
    @Override
    public Integer deleteByKey( Long key,  String corpid){
        return dao.deleteByKey(key , corpid);
    }
    @Override
    public ChartEntity getByKey( Long key,  String corpid){
        return dao.getByKey(key , corpid);
    }

    @Override
    public List<ChartEntity> findEntitys(Map<String ,Object>  param){
        return dao.findEntitys(param);
    }

    @Override
    public List<ChartEntity> findMutiEntitys(Map<String ,Object>  param){
        return dao.findMutiEntitys(param);
    }
    @Override
    public List<ChartEntity> findDiyEntitys(Map<String ,Object>  param){
        return dao.findDiyEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String ,Object>  param){
        return dao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public List<ChartEntity> getChartListByCategoryId(String corpid, Long categoryId){
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("corpid", corpid);
        param.put("del", DelEnum.NORMAL.getDel());
        param.put("categoryId", categoryId);
        return findEntitys(param);
    }

    @Override
    public boolean checkRepeat(String corpid, String name, Long setId, Integer chartType) {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("corpid", corpid);
        param.put("del", DelEnum.NORMAL.getDel());
        param.put("name", name);
        param.put("chartType", chartType);
        if (setId != null && setId > 0) {
            param.put("idNeq", setId);
        }
        Integer count = getEntitysCount(param);
        return count > 0;
    }

    @Override
    public List<ChartEntity> getList(String corpid, Integer enable, Integer chartType) {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("corpid", corpid);
        param.put("del", DelEnum.NORMAL.getDel());
        param.put("chartType", chartType);
        param.put("orderByStr", "sort desc, id asc");
        if (enable != null) {
            param.put("enable", enable);
        }
        return findEntitys(param);
    }

    @Override
    public ChartEntity getSearch(String corpid, Long categoryId) {
        Integer chartType = ChartTypeEnum.MULTIPLE_SEARCH.getCode();
        return  dao.getSearch(corpid,categoryId,chartType);
    }

    @Override
    public List<ChartEntity> getStockChartList() {
        return dao.getStockChartList();
    }

    /**
     * 批量更新enable
     * @param param 查询参数map
     * @author xingxing.xiao
     */
    @Override
    public void batchUpdateEnable(Map<String, Object> param) {
        dao.batchUpdateEnable(param);
    }
    
    @Override
    public void batchUpdateNumFormat(String corpid, List<Long> idIn, Integer numFormat) {
        dao.batchUpdateNumFormat(corpid, idIn, numFormat);
    }

    @Override
    public List<ChartEntity> getReturnStockChartList() {
        return dao.getReturnStockChartList();
    }

    @Override
    public void updateBatch(List<ChartEntity> chartEntityList, String corpid) {
        dao.updateBatch(chartEntityList, corpid);
    }

    @Override
    public void updateBatchNoCorpId(List<ChartEntity> chartEntityList) {
        dao.updateBatchNoCorpId(chartEntityList);
    }

    @Override
    public void  updateBatchAve(List<String> corpidIn) {
        dao.updateBatchAve(corpidIn);
    }

    /**
     * 批量更新图表的删除标识的值
     *
     * @param shouldDeleteIds
     * @param del
     */
    @Override
    public void updateBatchDeleteTag(List<Long> shouldDeleteIds, Integer del) {
        dao.updateBatchDeleteTag(shouldDeleteIds, del);
    }
}

 
